from django.db import models
from django.contrib.auth.models import User
from datetime import datetime

class Usuario(models.Model): #lo llamo usuario por no confundir con User de django
	nombre = models.CharField(max_length=30, blank = True)
	apellidos = models.CharField(max_length=30, blank = True)
	edad = models.DateField(blank = True)
	VAR_TYPE = ((1,'Usuario'),(2,'Bibliotecario'))
	perfil = models.IntegerField(choices=VAR_TYPE)
	user = models.OneToOneField(User, unique=True)

	def __unicode__(self):
		return self.nombre

class PosiblesEmails(models.Model):       
    emailPosible = models.EmailField(max_length=254, unique = True)
    
    def __unicode__(self):
        return str(self.emailPosible)
        
class Movie(models.Model):
	title = models.CharField(max_length=200)
	id_XML = models.CharField(max_length=500, blank=True)
	plot = models.CharField(max_length=3000)
	shortDescription = models.CharField(max_length=1000, blank = True)#viene en el XML pero no en el XSD
	lastModifiedDate = models.DateField(blank = True)
	publicWebUri = models.CharField(max_length=5000)
	artwork = models.CharField(max_length=5000, default="/static/images/missing.jpg")
	thumbnail = models.CharField(max_length=5000, default="/static/images/missing.jpg")
	classificationName = models.CharField(max_length=20)  #las opciones son +7, +13, +16, +18, T
	classificationAdult = models.BooleanField(default=False) 
	year = models.IntegerField(blank = True)
	duration = models.CharField(max_length=200, blank = True, default = '-') 
	isUserGenerated = models.BooleanField(default=False, blank = True) #viene en el XML pero no en el XSD
	applicationSpecificData = models.CharField(max_length=200, blank = True) #viene en el XML pero no en el XSD
	originalPublicationDate = models.DateField(blank = True) #viene en el XML pero no en el XSD
	trailer = models.CharField(max_length=5000, blank = True) #viene en el XML pero no en el XSD
	VAR_TYPE = ((1,'Admitido'),(2,'Rechazado'),(3,'Pendiente de examen'),(4,'No disponible'))
	status = models.IntegerField(choices=VAR_TYPE, default=3)
	genre = models.ManyToManyField('Genre', blank=True)
	director = models.ManyToManyField('Director', blank=True)
	actor = models.ManyToManyField('Actor', blank=True)
	
	def __unicode__(self):
		return self.title
   
class Genre(models.Model):
	genreName = models.CharField(max_length=60)

	def __unicode__(self):
		return self.genreName    

class Director(models.Model):
	directorName = models.CharField(max_length=100)
	def __unicode__(self):
		return self.directorName 
    
class Actor(models.Model):
	actorName = models.CharField(max_length=100)
	def __unicode__(self):
		return self.actorName 
    
class Score(models.Model):   
	movie = models.ForeignKey('Movie', blank=True)
	scoreValue = models.DecimalField(max_digits=5, decimal_places=2)
	scoreUrl = models.CharField(max_length=5000)
	
class PurchaseOption(models.Model):
	movie = models.ForeignKey('Movie') 
	offerType = models.CharField(max_length=60)
	price = models.DecimalField(max_digits=6, decimal_places=2)
	currency = models.CharField(max_length=10)
	videoQuality = models.CharField(max_length=10, null=True)
		
class Historial(models.Model):
	movie = models.ForeignKey('Movie') 
	usuario = models.ForeignKey('Usuario')    
	fecha = models.DateField(default=datetime.now())
	precio = models.DecimalField(max_digits=6, decimal_places=2) 

class Code(models.Model):    
	historial = models.ForeignKey('Historial', blank=True) 
	code = models.CharField(max_length=100)
	VAR_TYPE = ((1,'Usado'),(2,'No Usado'))  
	codeStatus = models.IntegerField(choices=VAR_TYPE)
    
class Biblioteca(models.Model):
	nombre =  models.CharField(max_length=100)
	dineroIngresado = models.DecimalField(max_digits=6, decimal_places=2) 
	fecha = models.DateField() #fecha para saber cuando ha establecido la pasta
	logo = models.FileField(upload_to='images', default="images/logoDefault.jpg")

	def __unicode__(self):
		return self.nombre